$(function () {
    if (editType != 'info') {
        regValidate(["#_bizDataForm"]);
    }
});

function doBizSave() {
    if(!$("#_bizDataForm").valid()) return;//校验不通过
    var name = $('#name').val();
    var sortNum = $('#sortNum').val();
    var remark = $('#remark').val();
    var postData = {
        name : name,
        sortNum : sortNum ? sortNum : 999,
        remark : remark,
    };
    var url = basePath + 'pvuv/statSeedBiz/addBiz?t=' + new Date().getTime();
    if (editType == 'edit') {
        postData.id = oneBizInfo.id;
        postData.seedId = oneBizInfo.seedId;
        postData.seedType = oneBizInfo.seedType;
        postData.bizId = oneBizInfo.bizId;
        url = basePath + 'pvuv/statSeedBiz/editBiz?t=' + new Date().getTime();
    } else {
        postData.seedId = searchInfo.seedId;
        postData.seedType = searchInfo.seedType;
        postData.bizId = $('#bizId').val();
    }
    $.ajax({
        type: 'post',
        url: url,
        dataType: 'json',
        data: postData,
        success : function (data) {
            if (!data) {
                toastr.error(common_save_fail);
                return;
            }
            if (data.result) {
                toastr.success(common_save_success);
                doBack();
                return;
            }
            if (!data.result) {
                toastr.error(data.message);
                return;
            }
        },
        error: function (request) {
            toastr.error(common_system_error);
            return;
        }
    });
}

function doBack() {
    window.location.href = basePath + 'pvuv/statSeedBiz/page?t=' + new Date().getTime() +
        '&' + searchParam.replace(/,/g, '&');
}

function doCheckDataChange() {
    var data = getFromData('#_bizDataForm');
    var checkData = {
        name : data.name,
        sortNum : data.sortNum,
        remark : data.remark,
    };
    if (editType == 'add') {
        checkData.bizId = data.bizId;
    }
    if (editType != 'info' && !Compare(checkData, oneBizInfo)) {
        swalClosePageToastr(doBack);
        return;
    }
    doBack();
}